package com.lft.freshordering.service.impl;
import com.lft.freshordering.entity.Goods;
import com.lft.freshordering.entity.Stypes;
import com.lft.freshordering.mapper.GoodsMapper;
import com.lft.freshordering.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tyhxzy
 * @since 2024-12-02
 */
@Service
public class GoodsServiceImpl implements IGoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public List<Goods> selectgoods() {
        List<Goods> selectgoods = goodsMapper.selectgoods();
        return selectgoods;
    }

    @Override
    public List<Stypes> selectByCategoryId(Integer categoryId) {
        Stypes xx = goodsMapper.selectstype(categoryId);
        List<Stypes> selectstype = new ArrayList<>();
        Stypes ss=new Stypes();
        ss.setGoods(goodsMapper.selectCategoryId(xx.getId()));
        ss.setId(xx.getId());
        ss.setTname(xx.getTname());
        selectstype.add(ss);
        return selectstype;
    }

    @Override
    public Goods getById(Integer id) {
        Goods getid = goodsMapper.getid(id);
        return getid;
    }

    @Override
    public int updategoods(Goods goods) {
        Integer updategoods = goodsMapper.updategoods(goods);
        return updategoods;
    }

    @Override
    public int instertgoods(Goods goods) {
        Integer instertgoods=null;
        Integer id=null;
        if(goods.getGoodsPics()==null){
            System.out.println("---------------------------null");
            instertgoods = goodsMapper.instertgoods(goods);

            return goods.getGoodsId();
        }
        if(goods.getGoodsPics()!=null){
            System.out.println("!-----------------------null");
            instertgoods = goodsMapper.updateimg(goods);
        }



        return instertgoods;
    }

    @Override
    public int deletegoods(Integer id) {
        int deletegoods = goodsMapper.deletegoods(id);
        return deletegoods;
    }

    @Override
    public int save(Goods goods) {
        int save = goodsMapper.save(goods);
        return save;
    }

    @Override
    public List<Goods> selectlike(String search) {
        List<Goods> goods = goodsMapper.selectLike(search);
        return goods;
    }

//    @Override
//    public int updateGoodsImageUrl(Integer id, String newImageUrl) {
//        Goods goods = new Goods();
//        goods.setGoodsId(id);
//        goods.setGoodsPics(newImageUrl);
//        //
//        int updateById = goodsMapper.updateById(goods);
//        return updateById;
//    }



}
